package com.xjtu.duansheli.controller;


import com.xjtu.duansheli.entity.IdentifyInfo;
import com.xjtu.duansheli.entity.UserInfo;
import com.xjtu.duansheli.json.AjaxResponse;
import com.xjtu.duansheli.service.IdentifyInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 漩涡鸣人
 * @since 2020-10-24
 */
@RestController
@RequestMapping("/project/identify-info")
@Api(value = "认证图片审批记录管理模块", description = "这是认证图片审批记录增删改查的模块")
public class IdentifyInfoController {

    @Autowired
    private IdentifyInfoService identifyInfoService;

    @ApiOperation(value = "获取全部审批记录", notes = "获取所有审批记录的信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页", required = false, defaultValue = "1", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "size", value = "每页数量", required = false, defaultValue = "10", paramType = "query", dataType = "int")
    })
    @RequestMapping(value = "/getIdenInfos", method = RequestMethod.GET)
    public AjaxResponse getAll(@RequestParam(value = "current") Integer current,
                               @RequestParam(value = "size") Integer size) {
        return AjaxResponse.success(identifyInfoService.getAllIdentifyInfo(current,size));
    }

    @ApiOperation(value = "根据id查找审批记录", notes = "获取根据id查找到的审批记录")
    @ApiImplicitParam(name = "id", value = "认证记录id", required = true, paramType = "query", dataType = "Long")
    @RequestMapping(value = "/getIdenInfoById", method = RequestMethod.GET)
    public AjaxResponse getIdenInfoById(@RequestParam(name = "id") Long id) {
        return AjaxResponse.success(identifyInfoService.getIdentifyInfoByid(id));
    }

    @ApiOperation(value = "根据图片id查找审批记录", notes = "获取根据图片id查找到的审批记录")
    @ApiImplicitParam(name = "imid", value = "图片id", required = true, paramType = "query", dataType = "Long")
    @RequestMapping(value = "/getIdenInfoByImId", method = RequestMethod.GET)
    public AjaxResponse getIdenInfoByImId(@RequestParam(name = "imid") Long imid) {
        return AjaxResponse.success(identifyInfoService.getIdentifyByImid(imid));
    }

    @ApiOperation(value = "添加审批记录信息", notes = "获取审批记录信息并且添加")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "result", value = "审批结果（0：驳回;1：通过）", required = true, paramType = "form", dataType = "int"),
            @ApiImplicitParam(name = "imageId", value = "审批图片id", required = true, paramType = "form", dataType = "Long")
    })
    @RequestMapping(value = "/addIdenInfo", method = RequestMethod.POST)
    public AjaxResponse addIdenImage(@RequestParam(value = "result") int result,
                                     @RequestParam(value = "imageId") Long imid,
                                     HttpServletRequest request) {
        UserInfo user = (UserInfo) request.getSession().getAttribute("loginUser");
        IdentifyInfo identifyInfo = new IdentifyInfo()
                .setResult(result)
                .setIdentifierId(user.getUid())
                .setImageId(imid);
        return AjaxResponse.success("数据库受影响行数->" + identifyInfoService.addIdentifyInfo(identifyInfo));
    }


    @ApiOperation(value = "删除审批记录信息", notes = "从数据库中删除某个审批记录")
    @ApiImplicitParam(name = "id", value = "删除审批记录id", required = true, paramType = "query", dataType = "Long")
    @RequestMapping(value = "/deleteIdenInfo", method = RequestMethod.DELETE)
    public AjaxResponse deleteIdenInfo(@RequestParam(value = "id") Long id) {
        return AjaxResponse.success("数据库受影响行数->" + identifyInfoService.deleteIdentifyInfo(id));
    }

    @ApiOperation(value = "审批记录总数量", notes = "获取数据库中审批记录总数量")
    @RequestMapping(value = "/getTotal", method = RequestMethod.GET)
    public AjaxResponse getTotal() {
        return AjaxResponse.success(identifyInfoService.getTotal());
    }

}

